package com.xinxin.leetcode.problem434;

/**
 * @author ShiXinXin
 * @date 2019-12-16 15:42
 */
class Solution {
    public int countSegments(String s) {
        s = s.trim();
        if (s.length() == 0) {
            return 0;
        }
        s += " ";
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == ' ' && s.charAt(i - 1) != ' ') {
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(new Solution().countSegments("Hello, my name is John"));
    }
}
